import os
import sys
import platform
import awtk_config as awtk

BIN_DIR=os.environ['BIN_DIR'];
TK_ROOT=os.environ['TK_ROOT'];
TK_3RD_ROOT=os.environ['TK_3RD_ROOT'];
GTEST_ROOT=os.environ['GTEST_ROOT'];

env=DefaultEnvironment().Clone();

INCLUDE_PATH = [TK_ROOT, 
  GTEST_ROOT,
  os.path.join(TK_ROOT, 'src'),  
  os.path.join(TK_3RD_ROOT, 'SDL/src'), 
  os.path.join(TK_3RD_ROOT, 'SDL/include'), 
  os.path.join(TK_ROOT, 'src/ext_widgets'),  
  os.path.join(TK_ROOT, '3rd/libunibreak'),
  os.path.join(GTEST_ROOT, 'src'),
  os.path.join(GTEST_ROOT, 'include'),
  os.path.join(GTEST_ROOT, 'make')]

env['CPPPATH'] = INCLUDE_PATH
env['LIBS'] = ['assets', 'image_gen', 'theme_gen', 'font_gen', 'str_gen', 'common', 'api_doc'] + awtk.STATIC_LIBS
env['LINKFLAGS'] = env['OS_SUBSYSTEM_CONSOLE'] + env['LINKFLAGS'];

SOURCES = [
 os.path.join(GTEST_ROOT, 'src/gtest-all.cc'),
] + Glob('*.cc') + Glob('*.c')

env['LIBS']=['debugger'] + env['LIBS']
env.Program(os.path.join(BIN_DIR, 'runTest'), SOURCES);
env.Program(os.path.join(BIN_DIR, 'recycle_test'), ["recycle_test.cpp"])
env.Program(os.path.join(BIN_DIR, 'waitable_action_queue_test'), ["waitable_action_queue_test.cpp"])
env.Program(os.path.join(BIN_DIR, 'waitable_ring_buffer_test'), ["waitable_ring_buffer_test.cpp"])
env.Program(os.path.join(BIN_DIR, 'action_thread_test'), ["action_thread_test.cpp"])
env.Program(os.path.join(BIN_DIR, 'app_conf_multi_threads'), ["app_conf_multi_threads.cpp"])
#env.Program(os.path.join(BIN_DIR, 'action_thread_pool_test'), ["action_thread_pool_test.cpp"])
env.Program(os.path.join(BIN_DIR, 'json_to_ubjson'), ["json_to_ubjson.cpp"])
env.Program(os.path.join(BIN_DIR, 'ubjson_to_json'), ["ubjson_to_json.cpp"])
env.Program(os.path.join(BIN_DIR, 'format_xml'), ["format_xml.cpp"])
env.Program(os.path.join(BIN_DIR, 'async_call_test'), ["async_call_test.cpp"])

env.SharedLibrary(os.path.join(BIN_DIR+"/plugins_for_test", 'a'), ["a.c"])
env.SharedLibrary(os.path.join(BIN_DIR+"/plugins_for_test", 'b'), ["b.c"])

OS_NAME = platform.system();
CROSS_COMPILE='CROSS_COMPILE' in os.environ and os.environ['CROSS_COMPILE'] == 'True'
if not CROSS_COMPILE:
  LIBS=env['LIBS']
  if OS_NAME != 'Windows':
    LIBS = LIBS + ['readline']
  env.Program(os.path.join(BIN_DIR, 'runFScript'), ["fscript_run.cpp"], LIBS=LIBS)

